/**
 * 服务器监控请求接口列表
 */
import http from '@/api'
import type { ApiDataResult, ApiPageResult, Paging } from '../interface'
import { getSysBase } from '@/config'
import type { Monitor } from './namespaces'
/**
 * 获取服务器信息接口
 * @returns {Promise<ApiDataResult<Monitor.Metric[]>>}
 */
export const getSystemInfoApi = (): Promise<ApiDataResult<Monitor.Metric[]>> => {
  return http.get(`monitor/systeminfo.json`, {}, { loading: false, baseURL: getSysBase() })
}

/**
 * 获取JVM信息接口
 * @returns {Promise<ApiDataResult<Monitor.Metric[]>>}
 */
export const getJvmInfoApi = (): Promise<ApiDataResult<Monitor.Metric[]>> => {
  return http.get(`monitor/jvminfo.json`, {}, { loading: false, baseURL: getSysBase() })
}

/**
 * 获取监控信息接口
 * @returns {Promise<ApiDataResult<Monitor.Metric>>}
 */
export const getMonitorInfoApi = (name: string): Promise<ApiDataResult<Monitor.Metric>> => {
  return http.get(`monitor/info.json`, { name: name }, { loading: false, baseURL: getSysBase() })
}

/**
 * 获取服务器硬盘使用情况信息接口
 * @returns {Promise<ApiDataResult<Map<string,any>[]>>}
 */
export const getDiskInfoApi = (): Promise<ApiDataResult<Monitor.DiskInfo[]>> => {
  return http.get(`monitor/diskinfo.json`, {}, { loading: false, baseURL: getSysBase() })
}

/**
 * 获取缓存信息接口
 * @returns {Promise<ApiDataResult<Monitor.Metric[]>>}
 */
export const getCacheInfoApi = (): Promise<ApiDataResult<Monitor.Metric[]>> => {
  return http.get(`monitor/cacheinfo.json`, {}, { loading: false, baseURL: getSysBase() })
}

/**
 * 获取缓存名称列表接口
 */
export const getCacheNamesApi = (): Promise<ApiPageResult<string>> => {
  return http.getList<string>(
    `monitor/cachenames.json`,
    {},
    { loading: false, baseURL: getSysBase() }
  )
}
/**
 * 清理缓存接口
 * @returns {Promise<ApiDataResult<boolean>>}
 */
export const getCacheClearApi = (name: string): Promise<ApiDataResult<Monitor.Metric[]>> => {
  return http.get(`monitor/cacheclear.json`, { name }, { loading: false, baseURL: getSysBase() })
}

/**
 * 获取http请求列表接口
 * @returns {Promise<ApiPageResult<Monitor.HttpTrace>>}
 */
export const getHttpTraceApi = ({
  pageNo,
  pageSize
}: Paging): Promise<ApiPageResult<Monitor.HttpTrace>> => {
  return http.getList<Monitor.HttpTrace>(
    `monitor/httptraces.json`,
    { pageNo, pageSize },
    { loading: false, baseURL: getSysBase() }
  )
}
